package com.help10000.rms.ui.activitys

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.amir.common.beans.CompanyEntity
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.help10000.rms.common.DialogUtil
import com.help10000.rms.mvp.presenter.CompanyListPresenter
import com.help10000.rms.mvp.presenter.SelectCompanyPresenter
import com.help10000.rms.mvp.view.CompanyListView
import com.help10000.rms.mvp.view.SelectCompanyView
import com.help10000.rms.ui.activitys.logins.LoginActivity
import com.help10000.rms.ui.base.BaseActivity
import com.help10000.rms.ui.utils.PageUtils
import kotlinx.android.synthetic.main.activity_relevance.*

/**
 * 关联员工
 */
class BindEmployeeActivity : BaseActivity<CompanyListPresenter, CompanyListView>(),
    CompanyListView,
    SelectCompanyView,
    View.OnClickListener {

    override fun createPresenter(): CompanyListPresenter {
        return CompanyListPresenter(this)
    }

    override fun getlayoutId(): Int {
        return R.layout.activity_relevance
    }

    override fun initView() {
        bindAccount.text = "${bindAccount.text}${SPUtils.getString(Constant.accountid)}"
    }

    override fun initListener() {
        btn_exit.setOnClickListener(DuplicateClickProxy(this))
        btn_apply.setOnClickListener(DuplicateClickProxy(this))
        finishBind.setOnClickListener(DuplicateClickProxy(this))

    }

    override fun initData(savedInstanceState: Bundle?) {

    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn_apply -> {

                PageUtils.jumpToActivity(this, ApplyEntryActivity::class.java)

            }
            R.id.btn_exit -> {
                SPUtils.remove(Constant.pwd)
                PageUtils.jumpToActivity(this, LoginActivity::class.java)
                finish()
            }
            R.id.finishBind -> {
                mPresenter.companyList()
            }
        }
    }

    override fun companyListData(t: CompanyEntity) {
        if (t.data.CmpyList.size == 1) {
            val selectCompanyPresenter = SelectCompanyPresenter(this)
            selectCompanyPresenter.companyLogin(t.data.CmpyList[0])
        } else if (t.data.CmpyList.size > 1) {
            /**
             * 跳转公司
             */
            val intent = Intent(mContext, SelectCompanyActivity::class.java)
            intent.putExtra("data", t.data)
            startActivity(intent)
        } else {
            DialogUtil.show(this, "未绑定任何公司")

        }
    }

    override fun companyLoginSuccess() {
        PageUtils.jumpToActivity(this, MainActivity::class.java)
        finish()
    }
}